package com.hot100;

public class h034 {
    public static void main(String[] args) {
        int[] nums ={1};
        int[] ints = searchRange(nums, 1);
        for(int i=0;i<ints.length;i++){
            System.out.println(ints[i]);
        }
    }

    public static int[] searchRange(int[] nums, int target) {
        int left = 0,right = nums.length-1;
        while (left <= right){
            int mid = (left + right)/2;
            if (nums[mid] == target){
                int l = mid,r = mid;
                while (l >= 0 && nums[l] == nums[mid])
                    l--;
                while (r <= nums.length-1 && nums[r] == nums[mid])
                    r++;
                return new int[]{l+1,r-1};
            }else if (target > nums[mid]){
                left = mid+1;
            }else {
                right = mid-1;
            }
        }
        return new int[]{-1,-1};
    }

}
